﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace System.Globalization
{

    public static class CultureInfoExtensions
    {

        private static List<KeyValuePair<int, string>> CultureNamesByLCID = new List<KeyValuePair<int, string>>()
        {
		    new KeyValuePair<int, string>(1, "ar"),
		    new KeyValuePair<int, string>(2, "bg"),
		    new KeyValuePair<int, string>(3, "ca"),
		    new KeyValuePair<int, string>(4, "zh-Hans"),
		    new KeyValuePair<int, string>(5, "cs"),
		    new KeyValuePair<int, string>(6, "da"),
		    new KeyValuePair<int, string>(7, "de"),
		    new KeyValuePair<int, string>(8, "el"),
		    new KeyValuePair<int, string>(9, "en"),
		    new KeyValuePair<int, string>(10, "es"),
		    new KeyValuePair<int, string>(11, "fi"),
		    new KeyValuePair<int, string>(12, "fr"),
		    new KeyValuePair<int, string>(13, "he"),
		    new KeyValuePair<int, string>(14, "hu"),
		    new KeyValuePair<int, string>(15, "is"),
		    new KeyValuePair<int, string>(16, "it"),
		    new KeyValuePair<int, string>(17, "ja"),
		    new KeyValuePair<int, string>(18, "ko"),
		    new KeyValuePair<int, string>(19, "nl"),
		    new KeyValuePair<int, string>(20, "no"),
		    new KeyValuePair<int, string>(21, "pl"),
		    new KeyValuePair<int, string>(22, "pt"),
		    new KeyValuePair<int, string>(23, "rm"),
		    new KeyValuePair<int, string>(24, "ro"),
		    new KeyValuePair<int, string>(25, "ru"),
		    new KeyValuePair<int, string>(26, "hr"),
		    new KeyValuePair<int, string>(27, "sk"),
		    new KeyValuePair<int, string>(28, "sq"),
		    new KeyValuePair<int, string>(29, "sv"),
		    new KeyValuePair<int, string>(30, "th"),
		    new KeyValuePair<int, string>(31, "tr"),
		    new KeyValuePair<int, string>(32, "ur"),
		    new KeyValuePair<int, string>(33, "id"),
		    new KeyValuePair<int, string>(34, "uk"),
		    new KeyValuePair<int, string>(35, "be"),
		    new KeyValuePair<int, string>(36, "sl"),
		    new KeyValuePair<int, string>(37, "et"),
		    new KeyValuePair<int, string>(38, "lv"),
		    new KeyValuePair<int, string>(39, "lt"),
		    new KeyValuePair<int, string>(40, "tg"),
		    new KeyValuePair<int, string>(41, "fa"),
		    new KeyValuePair<int, string>(42, "vi"),
		    new KeyValuePair<int, string>(43, "hy"),
		    new KeyValuePair<int, string>(44, "az"),
		    new KeyValuePair<int, string>(45, "eu"),
		    new KeyValuePair<int, string>(46, "hsb"),
		    new KeyValuePair<int, string>(47, "mk"),
		    new KeyValuePair<int, string>(50, "tn"),
		    new KeyValuePair<int, string>(52, "xh"),
		    new KeyValuePair<int, string>(53, "zu"),
		    new KeyValuePair<int, string>(54, "af"),
		    new KeyValuePair<int, string>(55, "ka"),
		    new KeyValuePair<int, string>(56, "fo"),
		    new KeyValuePair<int, string>(57, "hi"),
		    new KeyValuePair<int, string>(58, "mt"),
		    new KeyValuePair<int, string>(59, "se"),
		    new KeyValuePair<int, string>(60, "ga"),
		    new KeyValuePair<int, string>(62, "ms"),
		    new KeyValuePair<int, string>(63, "kk"),
		    new KeyValuePair<int, string>(64, "ky"),
		    new KeyValuePair<int, string>(65, "sw"),
		    new KeyValuePair<int, string>(66, "tk"),
		    new KeyValuePair<int, string>(67, "uz"),
		    new KeyValuePair<int, string>(68, "tt"),
		    new KeyValuePair<int, string>(69, "bn"),
		    new KeyValuePair<int, string>(70, "pa"),
		    new KeyValuePair<int, string>(71, "gu"),
		    new KeyValuePair<int, string>(72, "or"),
		    new KeyValuePair<int, string>(73, "ta"),
		    new KeyValuePair<int, string>(74, "te"),
		    new KeyValuePair<int, string>(75, "kn"),
		    new KeyValuePair<int, string>(76, "ml"),
		    new KeyValuePair<int, string>(77, "as"),
		    new KeyValuePair<int, string>(78, "mr"),
		    new KeyValuePair<int, string>(79, "sa"),
		    new KeyValuePair<int, string>(80, "mn"),
		    new KeyValuePair<int, string>(81, "bo"),
		    new KeyValuePair<int, string>(82, "cy"),
		    new KeyValuePair<int, string>(83, "km"),
		    new KeyValuePair<int, string>(84, "lo"),
		    new KeyValuePair<int, string>(86, "gl"),
		    new KeyValuePair<int, string>(87, "kok"),
		    new KeyValuePair<int, string>(90, "syr"),
		    new KeyValuePair<int, string>(91, "si"),
		    new KeyValuePair<int, string>(93, "iu"),
		    new KeyValuePair<int, string>(94, "am"),
		    new KeyValuePair<int, string>(95, "tzm"),
		    new KeyValuePair<int, string>(97, "ne"),
		    new KeyValuePair<int, string>(98, "fy"),
		    new KeyValuePair<int, string>(99, "ps"),
		    new KeyValuePair<int, string>(100, "fil"),
		    new KeyValuePair<int, string>(101, "dv"),
		    new KeyValuePair<int, string>(104, "ha"),
		    new KeyValuePair<int, string>(106, "yo"),
		    new KeyValuePair<int, string>(107, "quz"),
		    new KeyValuePair<int, string>(108, "nso"),
		    new KeyValuePair<int, string>(109, "ba"),
		    new KeyValuePair<int, string>(110, "lb"),
		    new KeyValuePair<int, string>(111, "kl"),
		    new KeyValuePair<int, string>(112, "ig"),
		    new KeyValuePair<int, string>(120, "ii"),
		    new KeyValuePair<int, string>(122, "arn"),
		    new KeyValuePair<int, string>(124, "moh"),
		    new KeyValuePair<int, string>(126, "br"),
		    new KeyValuePair<int, string>(127, ""),
		    new KeyValuePair<int, string>(128, "ug"),
		    new KeyValuePair<int, string>(129, "mi"),
		    new KeyValuePair<int, string>(130, "oc"),
		    new KeyValuePair<int, string>(131, "co"),
		    new KeyValuePair<int, string>(132, "gsw"),
		    new KeyValuePair<int, string>(133, "sah"),
		    new KeyValuePair<int, string>(134, "qut"),
		    new KeyValuePair<int, string>(135, "rw"),
		    new KeyValuePair<int, string>(136, "wo"),
		    new KeyValuePair<int, string>(140, "prs"),
		    new KeyValuePair<int, string>(145, "gd"),
		    new KeyValuePair<int, string>(1025, "ar-SA"),
		    new KeyValuePair<int, string>(1026, "bg-BG"),
		    new KeyValuePair<int, string>(1027, "ca-ES"),
		    new KeyValuePair<int, string>(1028, "zh-TW"),
		    new KeyValuePair<int, string>(1029, "cs-CZ"),
		    new KeyValuePair<int, string>(1030, "da-DK"),
		    new KeyValuePair<int, string>(1031, "de-DE"),
		    new KeyValuePair<int, string>(1032, "el-GR"),
		    new KeyValuePair<int, string>(1033, "en-US"),
		    new KeyValuePair<int, string>(1035, "fi-FI"),
		    new KeyValuePair<int, string>(1036, "fr-FR"),
		    new KeyValuePair<int, string>(1037, "he-IL"),
		    new KeyValuePair<int, string>(1038, "hu-HU"),
		    new KeyValuePair<int, string>(1039, "is-IS"),
		    new KeyValuePair<int, string>(1040, "it-IT"),
		    new KeyValuePair<int, string>(1041, "ja-JP"),
		    new KeyValuePair<int, string>(1042, "ko-KR"),
		    new KeyValuePair<int, string>(1043, "nl-NL"),
		    new KeyValuePair<int, string>(1044, "nb-NO"),
		    new KeyValuePair<int, string>(1045, "pl-PL"),
		    new KeyValuePair<int, string>(1046, "pt-BR"),
		    new KeyValuePair<int, string>(1047, "rm-CH"),
		    new KeyValuePair<int, string>(1048, "ro-RO"),
		    new KeyValuePair<int, string>(1049, "ru-RU"),
		    new KeyValuePair<int, string>(1050, "hr-HR"),
		    new KeyValuePair<int, string>(1051, "sk-SK"),
		    new KeyValuePair<int, string>(1052, "sq-AL"),
		    new KeyValuePair<int, string>(1053, "sv-SE"),
		    new KeyValuePair<int, string>(1054, "th-TH"),
		    new KeyValuePair<int, string>(1055, "tr-TR"),
		    new KeyValuePair<int, string>(1056, "ur-PK"),
		    new KeyValuePair<int, string>(1057, "id-ID"),
		    new KeyValuePair<int, string>(1058, "uk-UA"),
		    new KeyValuePair<int, string>(1059, "be-BY"),
		    new KeyValuePair<int, string>(1060, "sl-SI"),
		    new KeyValuePair<int, string>(1061, "et-EE"),
		    new KeyValuePair<int, string>(1062, "lv-LV"),
		    new KeyValuePair<int, string>(1063, "lt-LT"),
		    new KeyValuePair<int, string>(1064, "tg-Cyrl-TJ"),
		    new KeyValuePair<int, string>(1065, "fa-IR"),
		    new KeyValuePair<int, string>(1066, "vi-VN"),
		    new KeyValuePair<int, string>(1067, "hy-AM"),
		    new KeyValuePair<int, string>(1068, "az-Latn-AZ"),
		    new KeyValuePair<int, string>(1069, "eu-ES"),
		    new KeyValuePair<int, string>(1070, "hsb-DE"),
		    new KeyValuePair<int, string>(1071, "mk-MK"),
		    new KeyValuePair<int, string>(1074, "tn-ZA"),
		    new KeyValuePair<int, string>(1076, "xh-ZA"),
		    new KeyValuePair<int, string>(1077, "zu-ZA"),
		    new KeyValuePair<int, string>(1078, "af-ZA"),
		    new KeyValuePair<int, string>(1079, "ka-GE"),
		    new KeyValuePair<int, string>(1080, "fo-FO"),
		    new KeyValuePair<int, string>(1081, "hi-IN"),
		    new KeyValuePair<int, string>(1082, "mt-MT"),
		    new KeyValuePair<int, string>(1083, "se-NO"),
		    new KeyValuePair<int, string>(1086, "ms-MY"),
		    new KeyValuePair<int, string>(1087, "kk-KZ"),
		    new KeyValuePair<int, string>(1088, "ky-KG"),
		    new KeyValuePair<int, string>(1089, "sw-KE"),
		    new KeyValuePair<int, string>(1090, "tk-TM"),
		    new KeyValuePair<int, string>(1091, "uz-Latn-UZ"),
		    new KeyValuePair<int, string>(1092, "tt-RU"),
		    new KeyValuePair<int, string>(1093, "bn-IN"),
		    new KeyValuePair<int, string>(1094, "pa-IN"),
		    new KeyValuePair<int, string>(1095, "gu-IN"),
		    new KeyValuePair<int, string>(1096, "or-IN"),
		    new KeyValuePair<int, string>(1097, "ta-IN"),
		    new KeyValuePair<int, string>(1098, "te-IN"),
		    new KeyValuePair<int, string>(1099, "kn-IN"),
		    new KeyValuePair<int, string>(1100, "ml-IN"),
		    new KeyValuePair<int, string>(1101, "as-IN"),
		    new KeyValuePair<int, string>(1102, "mr-IN"),
		    new KeyValuePair<int, string>(1103, "sa-IN"),
		    new KeyValuePair<int, string>(1104, "mn-MN"),
		    new KeyValuePair<int, string>(1105, "bo-CN"),
		    new KeyValuePair<int, string>(1106, "cy-GB"),
		    new KeyValuePair<int, string>(1107, "km-KH"),
		    new KeyValuePair<int, string>(1108, "lo-LA"),
		    new KeyValuePair<int, string>(1110, "gl-ES"),
		    new KeyValuePair<int, string>(1111, "kok-IN"),
		    new KeyValuePair<int, string>(1114, "syr-SY"),
		    new KeyValuePair<int, string>(1115, "si-LK"),
		    new KeyValuePair<int, string>(1117, "iu-Cans-CA"),
		    new KeyValuePair<int, string>(1118, "am-ET"),
		    new KeyValuePair<int, string>(1121, "ne-NP"),
		    new KeyValuePair<int, string>(1122, "fy-NL"),
		    new KeyValuePair<int, string>(1123, "ps-AF"),
		    new KeyValuePair<int, string>(1124, "fil-PH"),
		    new KeyValuePair<int, string>(1125, "dv-MV"),
		    new KeyValuePair<int, string>(1128, "ha-Latn-NG"),
		    new KeyValuePair<int, string>(1130, "yo-NG"),
		    new KeyValuePair<int, string>(1131, "quz-BO"),
		    new KeyValuePair<int, string>(1132, "nso-ZA"),
		    new KeyValuePair<int, string>(1133, "ba-RU"),
		    new KeyValuePair<int, string>(1134, "lb-LU"),
		    new KeyValuePair<int, string>(1135, "kl-GL"),
		    new KeyValuePair<int, string>(1136, "ig-NG"),
		    new KeyValuePair<int, string>(1144, "ii-CN"),
		    new KeyValuePair<int, string>(1146, "arn-CL"),
		    new KeyValuePair<int, string>(1148, "moh-CA"),
		    new KeyValuePair<int, string>(1150, "br-FR"),
		    new KeyValuePair<int, string>(1152, "ug-CN"),
		    new KeyValuePair<int, string>(1153, "mi-NZ"),
		    new KeyValuePair<int, string>(1154, "oc-FR"),
		    new KeyValuePair<int, string>(1155, "co-FR"),
		    new KeyValuePair<int, string>(1156, "gsw-FR"),
		    new KeyValuePair<int, string>(1157, "sah-RU"),
		    new KeyValuePair<int, string>(1158, "qut-GT"),
		    new KeyValuePair<int, string>(1159, "rw-RW"),
		    new KeyValuePair<int, string>(1160, "wo-SN"),
		    new KeyValuePair<int, string>(1164, "prs-AF"),
		    new KeyValuePair<int, string>(1169, "gd-GB"),
		    new KeyValuePair<int, string>(2049, "ar-IQ"),
		    new KeyValuePair<int, string>(2052, "zh-CN"),
		    new KeyValuePair<int, string>(2055, "de-CH"),
		    new KeyValuePair<int, string>(2057, "en-GB"),
		    new KeyValuePair<int, string>(2058, "es-MX"),
		    new KeyValuePair<int, string>(2060, "fr-BE"),
		    new KeyValuePair<int, string>(2064, "it-CH"),
		    new KeyValuePair<int, string>(2067, "nl-BE"),
		    new KeyValuePair<int, string>(2068, "nn-NO"),
		    new KeyValuePair<int, string>(2070, "pt-PT"),
		    new KeyValuePair<int, string>(2074, "sr-Latn-CS"),
		    new KeyValuePair<int, string>(2077, "sv-FI"),
		    new KeyValuePair<int, string>(2092, "az-Cyrl-AZ"),
		    new KeyValuePair<int, string>(2094, "dsb-DE"),
		    new KeyValuePair<int, string>(2107, "se-SE"),
		    new KeyValuePair<int, string>(2108, "ga-IE"),
		    new KeyValuePair<int, string>(2110, "ms-BN"),
		    new KeyValuePair<int, string>(2115, "uz-Cyrl-UZ"),
		    new KeyValuePair<int, string>(2117, "bn-BD"),
		    new KeyValuePair<int, string>(2128, "mn-Mong-CN"),
		    new KeyValuePair<int, string>(2141, "iu-Latn-CA"),
		    new KeyValuePair<int, string>(2143, "tzm-Latn-DZ"),
		    new KeyValuePair<int, string>(2155, "quz-EC"),
		    new KeyValuePair<int, string>(3073, "ar-EG"),
		    new KeyValuePair<int, string>(3076, "zh-HK"),
		    new KeyValuePair<int, string>(3079, "de-AT"),
		    new KeyValuePair<int, string>(3081, "en-AU"),
		    new KeyValuePair<int, string>(3082, "es-ES"),
		    new KeyValuePair<int, string>(3084, "fr-CA"),
		    new KeyValuePair<int, string>(3098, "sr-Cyrl-CS"),
		    new KeyValuePair<int, string>(3131, "se-FI"),
		    new KeyValuePair<int, string>(3179, "quz-PE"),
		    new KeyValuePair<int, string>(4097, "ar-LY"),
		    new KeyValuePair<int, string>(4100, "zh-SG"),
		    new KeyValuePair<int, string>(4103, "de-LU"),
		    new KeyValuePair<int, string>(4105, "en-CA"),
		    new KeyValuePair<int, string>(4106, "es-GT"),
		    new KeyValuePair<int, string>(4108, "fr-CH"),
		    new KeyValuePair<int, string>(4122, "hr-BA"),
		    new KeyValuePair<int, string>(4155, "smj-NO"),
		    new KeyValuePair<int, string>(5121, "ar-DZ"),
		    new KeyValuePair<int, string>(5124, "zh-MO"),
		    new KeyValuePair<int, string>(5127, "de-LI"),
		    new KeyValuePair<int, string>(5129, "en-NZ"),
		    new KeyValuePair<int, string>(5130, "es-CR"),
		    new KeyValuePair<int, string>(5132, "fr-LU"),
		    new KeyValuePair<int, string>(5146, "bs-Latn-BA"),
		    new KeyValuePair<int, string>(5179, "smj-SE"),
		    new KeyValuePair<int, string>(6145, "ar-MA"),
		    new KeyValuePair<int, string>(6153, "en-IE"),
		    new KeyValuePair<int, string>(6154, "es-PA"),
		    new KeyValuePair<int, string>(6156, "fr-MC"),
		    new KeyValuePair<int, string>(6170, "sr-Latn-BA"),
		    new KeyValuePair<int, string>(6203, "sma-NO"),
		    new KeyValuePair<int, string>(7169, "ar-TN"),
		    new KeyValuePair<int, string>(7177, "en-ZA"),
		    new KeyValuePair<int, string>(7178, "es-DO"),
		    new KeyValuePair<int, string>(7194, "sr-Cyrl-BA"),
		    new KeyValuePair<int, string>(7227, "sma-SE"),
		    new KeyValuePair<int, string>(8193, "ar-OM"),
		    new KeyValuePair<int, string>(8201, "en-JM"),
		    new KeyValuePair<int, string>(8202, "es-VE"),
		    new KeyValuePair<int, string>(8218, "bs-Cyrl-BA"),
		    new KeyValuePair<int, string>(8251, "sms-FI"),
		    new KeyValuePair<int, string>(9217, "ar-YE"),
		    new KeyValuePair<int, string>(9225, "en-029"),
		    new KeyValuePair<int, string>(9226, "es-CO"),
		    new KeyValuePair<int, string>(9242, "sr-Latn-RS"),
		    new KeyValuePair<int, string>(9275, "smn-FI"),
		    new KeyValuePair<int, string>(10241, "ar-SY"),
		    new KeyValuePair<int, string>(10249, "en-BZ"),
		    new KeyValuePair<int, string>(10250, "es-PE"),
		    new KeyValuePair<int, string>(10266, "sr-Cyrl-RS"),
		    new KeyValuePair<int, string>(11265, "ar-JO"),
		    new KeyValuePair<int, string>(11273, "en-TT"),
		    new KeyValuePair<int, string>(11274, "es-AR"),
		    new KeyValuePair<int, string>(11290, "sr-Latn-ME"),
		    new KeyValuePair<int, string>(12289, "ar-LB"),
		    new KeyValuePair<int, string>(12297, "en-ZW"),
		    new KeyValuePair<int, string>(12298, "es-EC"),
		    new KeyValuePair<int, string>(12314, "sr-Cyrl-ME"),
		    new KeyValuePair<int, string>(13313, "ar-KW"),
		    new KeyValuePair<int, string>(13321, "en-PH"),
		    new KeyValuePair<int, string>(13322, "es-CL"),
		    new KeyValuePair<int, string>(14337, "ar-AE"),
		    new KeyValuePair<int, string>(14346, "es-UY"),
		    new KeyValuePair<int, string>(15361, "ar-BH"),
		    new KeyValuePair<int, string>(15370, "es-PY"),
		    new KeyValuePair<int, string>(16385, "ar-QA"),
		    new KeyValuePair<int, string>(16393, "en-IN"),
		    new KeyValuePair<int, string>(16394, "es-BO"),
		    new KeyValuePair<int, string>(17417, "en-MY"),
		    new KeyValuePair<int, string>(17418, "es-SV"),
		    new KeyValuePair<int, string>(18441, "en-SG"),
		    new KeyValuePair<int, string>(18442, "es-HN"),
		    new KeyValuePair<int, string>(19466, "es-NI"),
		    new KeyValuePair<int, string>(20490, "es-PR"),
		    new KeyValuePair<int, string>(21514, "es-US"),
		    new KeyValuePair<int, string>(25626, "bs-Cyrl"),
		    new KeyValuePair<int, string>(26650, "bs-Latn"),
		    new KeyValuePair<int, string>(27674, "sr-Cyrl"),
		    new KeyValuePair<int, string>(28698, "sr-Latn"),
		    new KeyValuePair<int, string>(28731, "smn"),
		    new KeyValuePair<int, string>(29740, "az-Cyrl"),
		    new KeyValuePair<int, string>(29755, "sms"),
		    new KeyValuePair<int, string>(30724, "zh"),
		    new KeyValuePair<int, string>(30740, "nn"),
		    new KeyValuePair<int, string>(30746, "bs"),
		    new KeyValuePair<int, string>(30764, "az-Latn"),
		    new KeyValuePair<int, string>(30779, "sma"),
		    new KeyValuePair<int, string>(30787, "uz-Cyrl"),
		    new KeyValuePair<int, string>(30800, "mn-Cyrl"),
		    new KeyValuePair<int, string>(30813, "iu-Cans"),
		    new KeyValuePair<int, string>(31748, "zh-Hant"),
		    new KeyValuePair<int, string>(31764, "nb"),
		    new KeyValuePair<int, string>(31770, "sr"),
		    new KeyValuePair<int, string>(31784, "tg-Cyrl"),
		    new KeyValuePair<int, string>(31790, "dsb"),
		    new KeyValuePair<int, string>(31803, "smj"),
		    new KeyValuePair<int, string>(31811, "uz-Latn"),
		    new KeyValuePair<int, string>(31824, "mn-Mong"),
		    new KeyValuePair<int, string>(31837, "iu-Latn"),
		    new KeyValuePair<int, string>(31839, "tzm-Latn"),
		    new KeyValuePair<int, string>(31848, "ha-Latn"),
		    new KeyValuePair<int, string>(4, "zh-CHS"),
		    new KeyValuePair<int, string>(31748, "zh-CHT")
        };

        public static CultureInfo GetCultureByLCID(this string extendee)
        {
            return GetCultureByLCID(Convert.ToInt16(extendee));
        }

        public static CultureInfo GetCultureByLCID(this int extendee)
        {
            var kvp = CultureNamesByLCID.FirstOrDefault(x => x.Key == extendee);
            if (kvp.Equals(default(KeyValuePair<int, string>)))
            {
                return CultureInfo.InvariantCulture;
            }
            return new CultureInfo(kvp.Value);
        }

    }

}